<?php

class Admin_m extends CI_Model {

    //put your code here
    function __construct() {
        parent::__construct();
        $this->load->database();
    }

    function login($email, $pass) {
        $this->db->select();
        $this->db->from('admin');
        $this->db->where(array('username' => $email));
        $this->db->where(array('password' => $pass));
        $query = $this->db->get();
        return $query;
    }

    function change_pass($data, $id) {
        return $this->db->update('admin', $data, array('id' => $id));
    }

    function is_password($pass, $idadmin) {
        $query = $this->db->get_where('admin', array('id' => $idadmin, 'password' => $pass));
        if ($query->num_rows() > 0) {
            return true;
        }
        return false;
    }

    function get_all_user($per_page,$off_set){
        $this->db->select();
        $this->db->from('admin');
        $this->db->where('id > 1 ');
        $this->db->limit($per_page,$off_set);
        $query = $this->db->get();
        return $query->result_array();
    }

    function count_all_user(){
        $this->db->select();
        $this->db->from('admin');
        $this->db->where('id > 1 ');
        $query = $this->db->get();
        return count($query->result_array());
    }
    function delete_admin($id) {
        return $this->db->delete('admin', array('id' => $id));
    }
    function add_admin($data) {
        return $this->db->insert('admin', $data);
    }
    function get_exist_username($username){
        $this->db->select();
        $this->db->from('admin');
        $this->db->where('username',$username);
        return  $this->db->get();
    }
}

?>
